﻿<template>
    <el-container>
        <el-header>
            <div class="left-panel">
                <el-button
                    type="primary"
                    v-if="orgType == 2"
                    icon="el-icon-plus"
                    v-show="addState"
                    @click="opAdd"
                >新增</el-button>
				<el-button
                    type="primary"
                    v-if="orgType == 1"
                    icon="el-icon-plus"
                    v-show="addState"
                    @click="onShowUpdatePrice"
                >修改价格</el-button>
				<el-button
                    type="primary"
                    icon="el-icon-plus"
                    v-if="orgType==1"
                    @click="openOperateLogs"
                >操作记录</el-button>
                <sc-file-import
                    v-if="orgType == 1"
                    ref="scFileImport"
                    :importUrl="'recovery-order/import'"
                    :templateUrl="'https://oss.jtmckj.com/Supply/Excel/kphs.xlsx'"
                ></sc-file-import>
                <!-- <el-button type="info" plain icon="el-icon-delete" v-show="deleteState" @click="opBatchDelete">删除</el-button> -->
            </div>
            <div class="right-panel">
                <el-button :icon="Search"   type="primary" @click="opBindData">查询</el-button>
                <el-button :icon="Search" type="info" plain @click="resetSearch">重置</el-button>
                <el-button text type="primary" @click="showCondition = !showCondition">
                    <span v-if="!showCondition">展开</span>
                    <span v-else>收起</span>
                    <vab-icon
                        class="vab-dropdown"
                        :class="{ 'vab-dropdown-active': fold }"
                        icon="arrow-up-s-line"
                    />
                </el-button>
            </div>
        </el-header>
        <el-foot v-show="showCondition">
            <vab-query-form-top-panel>
                <el-form inline label-width="49px" :model="queryForm" style="margin-top: 5px">
                    <el-form-item label="申请编号" label-width="100px">
                        <el-input
                            placeholder="---请输入申请编号---"
                            v-model="queryList.recoveryCode"
                            style="width: 300px"
                        />
                    </el-form-item>
                    <el-form-item label="申请单位" label-width="100px">
                        <el-input
                            placeholder="---请输入申请单位---"
                            v-model="queryList.storeName"
                            style="width: 300px"
                        />
                    </el-form-item>
                    <el-form-item label="申请时间" label-width="100px">
                        <el-date-picker
                            style="width: 300px"
                            v-model="queryList.protocolDates"
                            type="datetimerange"
                            value-format="YYYY-MM-DD HH:mm:ss"
                            format="YYYY-MM-DD HH:mm:ss"
                            range-separator="-"
                            unlink-panels="true"
                            start-placeholder="开始时间"
                            end-placeholder="结束时间"
                            :default-time="defaultTime"
                        />
                    </el-form-item>
                    <el-form-item label="申请人" label-width="100px">
                        <el-input
                            placeholder="---请输入申请人---"
                            v-model="queryList.applicant"
                            style="width: 300px"
                        />
                    </el-form-item>
                    <el-form-item label="单据状态" label-width="100px">
                        <el-select
                            placeholder="---请选择单据状态---"
                            v-model="queryList.processState"
                            style="width: 300px"
                        >
                            <el-option label="---请选择---" value />
                            <el-option
                                v-for="item in optionsState"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value"
                            />
                        </el-select>
                    </el-form-item>
                    <el-form-item
                        v-if="orgType != 1"
                        label-width="100px"
                        label="回收单位"
                        prop="purchaseUnityId"
                    >
                        <el-select
                            placeholder="---请输入名称---"
                            v-model="queryList.purchaseUnityId"
                            style="width: 300px"
                        >
                            <el-option
                                v-for="item in optionsPurchaseUnity"
                                :key="item.purchaseUnityId"
                                :label="item.purchaseUnityName"
                                :value="item.purchaseUnityId"
                            />
                        </el-select>
                    </el-form-item>
                    <el-form-item label="回收方式" label-width="100px">
                        <el-select
                            placeholder="---请选择回收方式---"
                            v-model="queryList.recoveryType"
                            style="width: 300px"
                        >
                            <el-option label="---请选择---" value />
                            <el-option
                                v-for="item in optionsRecoveryType"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value"
                            />
                        </el-select>
                    </el-form-item>
                    <el-form-item label="物流单号" label-width="100px">
                        <el-input
                            placeholder="---请输入名称---"
                            v-model="queryList.logisticsNum"
                            style="width: 300px"
                        />
                    </el-form-item>
                    <el-form-item label="供应商" label-width="100px">
                        <scSupplierSelect ref="selectRef" />
                    </el-form-item>
                    <el-form-item label="物料简码" label-width="100px">
                        <el-input
                            placeholder="---请输入物料简码---"
                            v-model="queryList.materialSimpCode"
                            style="width: 300px"
                        />
                    </el-form-item>
                    <el-form-item label="物料编码" label-width="100px">
                        <el-input
                            placeholder="---请输入物料编码---"
                            v-model="queryList.materialCode"
                            style="width: 300px"
                        />
                    </el-form-item>
                    <el-form-item label="物料分类" label-width="100px">
                        <el-tree-select
                            v-model="queryList.materialTypeIds"
                            placeholder="---请选择物料分类---"
                            collapse-tags
                            collapse-tags-tooltip
                            :props="{ label: 'label', value: 'value', children: 'children' }"
                            :data="materialTypeTree"
                            multiple
                            :render-after-expand="false"
                            show-checkbox
                            style="width: 300px"
                        />
                    </el-form-item>
                    <el-form-item label="物料名称" label-width="100px">
                        <el-input
                            placeholder="---请输入物料名称---"
                            v-model="queryList.materialName"
                            style="width: 300px"
                        />
                    </el-form-item>
                    <!-- <el-form-item label="物料名称" label-width="100px">
						<el-input placeholder="---请输入名称---" v-model="queryList.materialName" style="width: 300px" />
					</el-form-item>
					<el-form-item label="物料编码" label-width="100px">
						<el-input placeholder="---请输入名称---" v-model="queryList.materialCode" style="width: 300px" />
                    </el-form-item>-->
                </el-form>
            </vab-query-form-top-panel>
        </el-foot>

        <el-main class="nopadding">
            <scTable
                ref="mytable"
                :queryType="'recovery-order/pages'"
                :data="listData"
                :queryList="queryList"
                :column="columnList"
                :orderList="OrderList"
                :sort-orders="['ascending', 'descending']"
                @selection-change="selectionChange"
                row-key="deliveryProtocolId"
                key="deliveryProtocolId"
                stripe
                show-summary
                remoteSummary
            >
                <el-table-column type="selection"></el-table-column>
                <el-table-column label="序号" type="index" align="center" width="80" sortable></el-table-column>
                <el-table-column
                    label="回收时间"
                    prop="recoveryTime"
                    align="center"
                    width="160"
                    sortable
                >
                    <template #default="scope">{{scope.row.recoveryTime?.slice(0,10)}}</template>
                </el-table-column>
                <el-table-column
                    label="物料名称"
                    prop="materialName"
                    align="center"
                    width="250"
                    sortable
                ></el-table-column>
                <el-table-column
                    label="申请数量"
                    prop="recoveryCount1"
                    align="center"
                    width="140"
                    sortable
                ></el-table-column>

                <el-table-column
                    label="门店单价"
                    prop="recoveryPrice"
                    align="center"
                    width="120"
                    sortable
                    v-if="this.orgType == 1 || this.orgType == 2"
                ></el-table-column>
                <el-table-column
                    label="供应商单价"
                    prop="reSupplierPrice"
                    align="center"
                    width="130"
                    sortable
                    v-if="this.orgType == 1 || this.orgType == 3"
                ></el-table-column>

                <el-table-column
                    label="集采确认有效数量"
                    prop="recoveryCount3"
                    align="center"
                    width="160"
                    sortable
                ></el-table-column>
                <el-table-column
                    label="供应商确认有效数量"
                    prop="recoveryCount3"
                    align="center"
                    width="175"
                    sortable
                ></el-table-column>
                <el-table-column
                    label="门店有效金额"
                    align="center"
                    width="150"
                    sortable
                    v-if="this.orgType == 1 || this.orgType == 2"
                >
                    <template #default="scope">{{scope.row.recoveryPrice* scope.row.recoveryCount3}}</template>
                </el-table-column>
                <el-table-column
                    label="供应商有效金额"
                    align="center"
                    width="150"
                    sortable
                    v-if="this.orgType == 1 || this.orgType == 3"
                >
                    <template
                        #default="scope"
                    >{{scope.row.reSupplierPrice* scope.row.recoveryCount3}}</template>
                </el-table-column>

                <el-table-column label="申请单位" prop="storeName" align="center" width="160" sortable></el-table-column>

                <el-table-column
                    label="申请编号"
                    prop="recoveryCode"
                    align="center"
                    width="160"
                    sortable
                ></el-table-column>
                <el-table-column
                    label="供应商"
                    prop="recoverySuplyName"
                    align="center"
                    width="240"
                    sortable
                ></el-table-column>
                <el-table-column
                    label="物料编码"
                    prop="materialCode"
                    align="center"
                    width="250"
                    sortable
                ></el-table-column>

                <el-table-column label="申请人" prop="applicant" align="center" width="180" sortable></el-table-column>
                <el-table-column
                    label="回收单位"
                    prop="purchaseUnityName"
                    align="center"
                    width="220"
                    sortable
                ></el-table-column>
                <el-table-column
                    label="回收方式"
                    prop="recoveryType"
                    align="center"
                    width="140"
                    sortable
                >
                    <template #default="scope">
                        <div
                            style="color: #4592b8"
                            type="success"
                            effect="dark"
                            v-if="scope.row.recoveryType == 1"
                        >邮寄</div>
                        <div
                            style="color: #4592b8"
                            type="success"
                            effect="dark"
                            v-if="scope.row.recoveryType == 2"
                        >酒商上门回收</div>
                    </template>
                </el-table-column>
                <el-table-column
                    label="期望上门时间"
                    prop="expectedDate"
                    align="center"
                    width="160"
                    sortable
                >
                    <template #default="scope">{{scope.row.expectedDate?.slice(0,10)}}</template>
                </el-table-column>
                <!-- <el-table-column label="物流单号" prop="logisticsNum" align="center" width="200" sortable></el-table-column>
                <el-table-column label="物流公司" prop="logisticsName" align="center" width="200" sortable></el-table-column>-->
                <el-table-column
                    label="单据状态"
                    prop="processState"
                    align="center"
                    width="120"
                    sortable
                >
                    <template #default="scope">
                        <div type="primary" effect="dark" v-if="scope.row.processState == 0">门店提交</div>
                        <div type="success" effect="dark" v-if="scope.row.confirmStatus == 1">供应商已确认</div>
                        <div type="success" effect="dark" v-if="scope.row.confirmStatus == 0">供应商待确认</div>
                        <div
                            type="success"
                            effect="dark"
                            v-if="scope.row.processState == 3"
                        >供应商退回待分配</div>
                        <div type="success" effect="dark" v-if="scope.row.processState == 4">集采中心退回</div>
                    </template>
                </el-table-column>

                <!-- <el-table-column label="申请时间" prop="createTime" align="center" width="160" sortable></el-table-column> -->
                <!-- <el-table-column label="回收日期" prop="recoveryTime" align="center" width="120" sortable>
					<template #default="scope">{{scope.row.recoveryTime?.slice(0, 10)}}</template>
                </el-table-column>-->

                <!-- <el-table-column label="供应商确认有效数量" prop="recoveryCount2" align="center" width="140"
                sortable></el-table-column>-->
                <!-- <el-table-column label="空瓶标识码" prop="materialBarCode" align="center" width="180"
                sortable></el-table-column>-->

                <!-- <el-table-column label="有效金额" prop="recoverPriceTotal" align="center" width="180"
					sortable></el-table-column>
				<el-table-column label="酒商确认数量" prop="recoveryCount3" align="center" width="160"
					sortable></el-table-column>
                <el-table-column label="备注" prop="remark" align="center" width="200" sortable></el-table-column>-->

                <el-table-column label="操作" fixed="right" align="center" width="240">
                    <template #default="scope">
                        <el-button-group>
                            <!-- 酒业admin 步骤2 -->
                            <!-- <el-button v-if="orgType == 1 && scope.row.processState == 0" text type="primary" size="small" @click="opDelete(scope.row, scope.$index)">删除</el-button> -->
                            <!-- <el-button v-if="orgType == 1 &&(scope.row.processState == 0||scope.row.processState == 3) "
								text type="primary" size="small"
								@click="opCheck(scope.row, scope.$index)">确认</el-button>
							<el-button v-if="orgType == 1 &&(scope.row.processState == 0||scope.row.processState == 3) "
                            text type="primary" size="small" @click="opDone(scope.row, scope.$index)">终止</el-button>-->

                            <!-- 门店 步骤1 -->
                            <!-- <el-button v-if="orgType == 2 && scope.row.processState == 0" text type="primary"
								size="small" @click="opDelete(scope.row, scope.$index)">删除</el-button>
							<el-button v-if="orgType == 2 && scope.row.processState == 0" text type="primary"
                            size="small" @click="opedIt(scope.row, scope.$index)">修改</el-button>-->

                            <!-- 酒商/供应商 步骤3   ===1代表已确定  未验证 !== 1 或者 ===2 -->
                            <!--  <el-button v-if="orgType == 3 && scope.row.processState !== 1" text type="primary" size="small" @click="opDelete(scope.row, scope.$index)">删除</el-button> -->
                            <el-button
                                v-if="orgType == 3 && scope.row.confirmStatus == 0"
                                text
                                type="primary"
                                size="small"
                                @click="opShow(scope.row, scope.$index)"
                            >确认</el-button>
                            <el-button
                                v-if="orgType == 1 && scope.row.processState == 0"
                                text
                                type="primary"
                                size="small"
                                @click="onShowAudit(scope.row, scope.$index)"
                            >审核</el-button>
                            <el-button
                                v-if="orgType == 3 && scope.row.recoveryType == 1 && scope.row.processState == 1"
                                text
                                type="primary"
                                size="small"
                                @click="opLogistics(scope.row, scope.$index)"
                            >物流</el-button>
                            <el-button
                                text
                                type="primary"
                                size="small"
                                @click="opView(scope.row, scope.$index)"
                            >查看</el-button>
                        </el-button-group>
                    </template>
                </el-table-column>
            </scTable>
        </el-main>
    </el-container>

    <!-- 供应商/酒商  确认操作弹框 -->
    <el-dialog v-if="dialogVisible" v-model="dialogVisible" title="空瓶回收确认" :width="430">
        <div style="padding-left: 30px">
            <div class="lable-row">
                <div class="w-100">空瓶名称：</div>
                <div>{{ digForm.materialName }}</div>
            </div>
            <div class="lable-row">
                <span class="w-100">空瓶标识码：</span>
                <el-input v-model="digForm.materialBarCode" style="width: 230px" placeholder="请输入" />
            </div>
            <div class="lable-row">
                <div class="w-100">回收数量：</div>
                <div>{{ digForm.recoveryCount1 }}</div>
            </div>
            <div class="lable-row">
                <div class="w-100">备注：</div>
                <div>{{ digForm.remark }}</div>
            </div>
            <div class="lable-row">
                <div class="w-100">供应商：</div>
                <div>{{ digForm.recoverySuplyName }}</div>
            </div>
            <div class="lable-row">
                <span class="w-100">酒商确认数量：</span>
                <el-input
                    :disabled="jsStaus"
                    v-model.number="digForm.recoveryCount3"
                    style="width: 230px; margin-left: 0px"
                    placeholder="请输入"
                />
            </div>
            <div class="lable-row">
                <span class="w-100">集采确认数量：</span>
                <el-input
                    :disabled="jyStaus"
                    v-model.number="digForm.recoveryCount2"
                    style="width: 230px; margin-left: 0px"
                    placeholder="请输入"
                />
            </div>
        </div>
        <template #footer>
            <div style="text-align: center;">
                <el-button @click="dialogVisible = false">取消</el-button>
                <el-button type="primary" @click="confirmSubmit" v-if="orgType != 2">确认</el-button>

                <el-button type="primary" v-else>确认</el-button>
            </div>
        </template>
    </el-dialog>

    <!-- 新增/编辑 回收空瓶 -->
    <reco-Dialog ref="customDialog" :title="title" @success="success"></reco-Dialog>

    <!-- 回收空瓶确认弹窗 -->
    <check ref="checkDialog" @success="success"></check>
    <confirm-dialog ref="confirmDialog" @success="success"></confirm-dialog>
    <logistics-dialog ref="logisticsDialog" @success="success"></logistics-dialog>

    <!-- 回收空瓶审核弹窗 -->
    <audit ref="auditDialog" @success="success"></audit>
    <!-- 回收空瓶价格修改 -->
    <updatePrice ref="updatePriceDialog" @success="success"></updatePrice>
	<!-- 操作日志列表 -->
	<operateLogs v-if="dialogOperateLogs" ref="operateLogsDialog" @closed="dialogOperateLogs = false"></operateLogs>
</template>

<script>
import tool from "@/utils/tool";
import recoDialog from "./modules/recoDialog.vue";
import check from "./modules/check.vue";
import confirmDialog from "./modules/confirm.vue";
import audit from "./modules/audit.vue";
import updatePrice from "./modules/updatePrice.vue";
import logisticsDialog from "./modules/logistics.vue";
export default {
    name: "revoceryIndex",
    components: {
        recoDialog,
        check,
        confirmDialog,
        logisticsDialog,
        audit,
        updatePrice,
    },
    data() {
        return {
            showCondition: false,
            selectionRows: [],
            columnList: [],
            OrderList: {
                deliveryProtocolId: "Asc",
            },
            queryList: {},
            result: "", // 运行结果
			dialogOperateLogs:false,
            addState: true, //可以增加
            editBatchState: true, //可以批量修改
            deleteState: true, //可以删除
            optionsState: [],
            optionsRecoveryType: [],
            materialTypeTree: [],
            dialogVisible: false,
            optionsPurchaseUnity: [],
            digForm: {},
            Id: null,
            orgType: "",
            processState: null,
            jsStaus: false, //酒商控制状态
            jyStaus: false, //酒业控制状态
            recoveryString: "",
            title: "",
            defaultTime: [
                new Date(2000, 1, 1, 0, 0, 0),
                new Date(2000, 2, 1, 23, 59, 59),
            ],
        };
    },
    methods: {
        //更新空瓶回收确认
        async confirmSubmit() {
            try {
                // 1. 酒业   orgType 1
                // 2. 门店
                // 3. 供应商   orgType 3酒商
                //processState 0 可以操作酒商， 2可以操作酒业，不能修改酒商

                //判断orgType等于3可以操作酒商，不能操作酒业 ， 断orgType等于1可以操作酒业，不能操作酒商

                // orgType判断等于1可以操作酒业，并且processState等于2 可以操作酒业 ，不能操作酒商，
                // orgType判断等于3可以操作酒商, 并且processState等于0 可以操作酒商，不能修改酒商

                // 判断是否可以操作酒业
                if (
                    (this.orgType === 1 && this.processState === 2) ||
                    (this.orgType === 3 && this.processState === 0)
                ) {
                    this.jyStaus = true; // 可以操作酒业
                } else {
                    this.jyStaus = false; // 不能操作酒业
                }

                // 判断是否可以操作酒商
                if (
                    (this.orgType === 1 && this.processState === 0) ||
                    (this.orgType === 3 && this.processState === 2)
                ) {
                    this.jsStaus = true; // 可以操作酒商
                } else {
                    this.jsStaus = false; // 不能操作酒商
                }

                var returnValue = await this.$API.auth.PostProcessApi.post(
                    "recovery-order/updateprocessstate",
                    {
                        recoveryId: this.Id,
                        ...this.digForm,
                    }
                );
                if (returnValue.status == 200) {
                    this.dialogVisible = false;
                    this.$refs.mytable.getData();
                    console.log(this.orgType, "orgType");
                } else {
                    this.$message.error("操作失败:" + returnValue.msg);
                }
            } catch (error) {
                return false;
            }
        },
        //显示审核
        onShowAudit(row) {
            this.$refs.auditDialog.open(row);
        },
		//显示价格修改
		onShowUpdatePrice(row) {
			if (this.selectionRows.length == 0) {
                this.$message.error("请选择要操作的订单");
                return;
            }

            if (this.selectionRows.length > 1) {
                this.$message.error("只能选择一项进行操作！");
                return;
            }
            this.$refs.updatePriceDialog.open(this.selectionRows[0]);
        },
        opCheck(row, index) {
            this.$refs.checkDialog.initData(row);
        },
        async opDone(row, index) {
            //获取状态
            try {
                var returnValue = await this.$API.auth.PostProcessApi.post(
                    "recovery-order/done",
                    {
                        ids: row.recoveryId,
                    }
                );
                if (returnValue.status == 200) {
                    this.opBindData();
                } else {
                    this.$message.error("操作失败:" + returnValue.msg);
                }
            } catch (error) {
                this.loading = false;
                return false;
            }
            console.log(row);
        },
        //确认
        opShow(row, v) {
            this.$refs.confirmDialog.open(row);
            // console.log(row, 'row-------------')
            // this.dialogVisible = true;
            // this.Id = row.recoveryId;
            // this.digForm = JSON.parse(JSON.stringify(row));
            // this.processState = row.processState;
            // console.log(this.orgType, 'orgType-------------')
            // if (this.orgType === 1) {
            // 	this.digForm.processState = 2;
            // 	this.jsStaus = true; // 禁用操作酒商
            // 	this.jyStaus = false; // 操作酒业
            // }
            // if (this.orgType === 3) {
            // 	this.digForm.processState = 1;
            // 	this.jyStaus = true; // 禁用操作酒业
            // 	this.jsStaus = false; // 操作酒商
            // }
            // if (this.orgType === 2) {
            // 	this.jsStaus = true; // 禁用操作酒商
            // 	this.jyStaus = true; // 禁用操作酒业
            // }
        },
        //物流
        opLogistics(row) {
            this.$refs.logisticsDialog.open(row);
        },
        //查看
        opView(row) {
            this.$refs.confirmDialog.show(row);
        },
        async initOptions() {
            //获取状态
            try {
                var returnValue = await this.$API.auth.PostProcessApi.post(
                    "base-dictionary/options",
                    {
                        Codes: ["RecoveryProcessState"],
                    }
                );
                if (returnValue.status == 200) {
                    this.optionsState = returnValue.response.find(
                        (p) => p.code == "RecoveryProcessState"
                    ).optionsDetails;
                } else {
                    this.$message.error("操作失败:" + returnValue.msg);
                }
            } catch (error) {
                this.loading = false;
                return false;
            }

            try {
                //获取回收单位
                var returnValue = await this.$API.auth.GetProcessApi.get(
                    "purchase-unity/list"
                );
                if (returnValue.status == 200) {
                    this.optionsPurchaseUnity = returnValue.response;
                    this.queryList.pId =
                        this.optionsPurchaseUnity[0].purchaseUnityId;
                } else {
                    this.$message.error("操作失败:" + returnValue.msg);
                }
            } catch (error) {
                this.loading = false;
                return false;
            }
            try {
                //获取回收方式
                var returnValue = await this.$API.auth.PostProcessApi.post(
                    "base-dictionary/options",
                    {
                        Codes: ["RecoveryType"],
                    }
                );
                if (returnValue.status == 200) {
                    this.optionsRecoveryType = returnValue.response.find(
                        (p) => p.code == "RecoveryType"
                    ).optionsDetails;
                } else {
                    this.$message.error("操作失败:" + returnValue.msg);
                }
            } catch (error) {
                this.loading = false;
                return false;
            }
        },
        opAdd() {
            this.title = "新增回收空瓶";
            this.$refs.customDialog.openDialog();
        },
        //编辑
        opedIt(row) {
            console.log(row, "sssssssssssssssxxxxxxxxxxxx");
            this.title = "编辑回收空瓶";
            this.$refs.customDialog.openDialog(row);
            // //编辑数据回显
            // this.$refs.customDialog.formData = { ...row }
        },
        success() {
            this.$refs.mytable.getData();
        },
        //删除
        async opDelete(row) {
            console.log(row);
            try {
                var returnValue = await this.$API.auth.PostProcessApi.post(
                    "recovery-order/delete",
                    {
                        ids: row.recoveryId,
                    }
                );
                if (returnValue.status == 200) {
                    this.$message.success("操作成功");
                    this.$refs.mytable.getData();
                } else {
                    this.$message.error("操作失败:" + returnValue.msg);
                }
            } catch (error) {
                this.loading = false;
                return false;
            }
        },
        //批量删除
        async opBatchDelete() {
            if (this.selectionRows.length > 0) {
                this.$confirm(
                    `确定删除选中的 ${this.selectionRows.length} 项吗？`,
                    "提示",
                    {
                        type: "warning",
                    }
                )
                    .then(async () => {
                        const deliveryProtocolIds = this.selectionRows
                            .map((p) => p.recoveryId)
                            .join(",");
                        console.log(deliveryProtocolIds, "deliveryProtocolIds");
                        try {
                            var returnValue =
                                await this.$API.auth.PostProcessApi.post(
                                    "recovery-order/delete",
                                    {
                                        ids: deliveryProtocolIds,
                                    }
                                );
                            if (returnValue.status == 200) {
                                this.$message.success("操作成功");
                                this.$refs.mytable.getData();
                            } else {
                                this.$message.error(
                                    "操作失败:" + returnValue.msg
                                );
                            }
                        } catch (error) {
                            this.loading = false;
                            return false;
                        }
                    })
                    .catch(() => {});
            } else {
                this.$message.error("请选择要删除的选项");
            }
        },
        //表格选择后回调事件
        selectionChange(selection) {
            this.selectionRows = selection;
        },
        async opBindData() {
            console.log(
                this.$refs.selectRef.orgcodevalue,
                "this.$refs.selectRef.orgcodevalue"
            );
            let arr = this.$refs.selectRef.orgcodevalue;
            // 使用 map 和 join 方法将数组转换成字符串
            this.recoveryString = arr.map((item) => item.supplierId).join(",");
            this.queryList.recoverySuplyId = this.recoveryString;
            if (this.queryList.protocolDates) {
                this.queryList.recoveryStartTime =
                    this.queryList.protocolDates[0];
                this.queryList.recoveryEndTime =
                    this.queryList.protocolDates[1];
            }
            this.queryList.storeIds = [];
            if (
                this.queryList &&
                this.queryList.stores &&
                this.queryList.stores.length > 0
            ) {
                this.queryList.stores.map((p) =>
                    this.queryList.storeIds.push(p.storeId)
                );
            }
            this.$refs.mytable.clearSort();
            this.$refs.mytable.getData();
        },
        resetSearch() {
            this.$refs.selectRef.orgcodevalue = [];
            this.queryList = {};
            this.$refs.mytable.getData();
        },

        async orgSelectProcess(rowData) {
            this.queryList.stores = [];
            this.queryList.storeIds = [];
            if (rowData && rowData.length > 0) {
                rowData.map((p, index) => {
                    if (p) {
                        this.queryList.stores = [
                            ...this.queryList.stores,
                            {
                                storeId: p.storeId,
                                storeName: p.storeName,
                            },
                        ];
                        this.queryList.storeIds = [
                            ...this.queryList.storeIds,
                            p.storeId,
                        ];
                    }
                });
            }
            await this.opBindData();
        },
		//操作日志
        async openOperateLogs() {
            if (this.selectionRows.length == 0) {
                this.$message.error("请选择要操作的订单");
                return;
            }
            const recoveryIds=this.selectionRows.map(p=>p.recoveryId);
            this.dialogOperateLogs = true;
            console.log(this.dialogOperateLogs);
            this.$nextTick(() => {
                this.$refs.operateLogsDialog.setData({operateOrderType:4, operateOrderIds:recoveryIds});
                this.$refs.operateLogsDialog.open("operateLog");
            });
        },
    },
    async mounted() {
        this.orgType = tool.data.get("USER_INFO").AccountType;
        var recoveryCode = this.$route.query.recoveryCode;
        if (recoveryCode) {
            this.queryList.recoveryCode = recoveryCode;
        }
        try {
            const returnValue = await this.$API.auth.PostProcessApi.post(
                "material-type/tree",
                {
                    status: 1,
                }
            );
            if (returnValue.status == 200) {
                this.materialTypeTree = returnValue.response;
            } else {
                this.$message.error("操作失败:" + returnValue.msg);
            }
        } catch (error) {}
        await this.initOptions();
        await this.opBindData();
    },
};
</script>

<style scoped>
.lable-row {
    display: flex;
    align-items: center;
    margin-top: 20px;
}

.w-100 {
    width: 100px;
}

::v-deep .el-input {
    height: 38px;
}

::v-deep .el-table__footer .cell {
    display: none;
}
</style>
